n=int(input())
maxx=0
k=0
if 100000>n>999:
    for i in range (2, int(n**0.5)+1):
        if n%i==0:
            k+=1
    if k==0:
        maxx=max(maxx, n)
    else:
        k=0   
        a=n%10 #единицы
        if a>0 and a!=0:
            for i in range(2,int(a**0.5)+1):
                if a%i==0:
                     k+=1
            if k==0:
                maxx=max(maxx, a)
            else:
                k=0
                    
        n=n//10
        b=n%10 #десятки
        if b>0 and b!=0:
            for i in range(2,int(b**0.5)+1):
                if b%i==0:
                     k+=1
            if k==0:
                maxx=max(maxx, b)
            else:
                k=0
        n=n//10
        c=n%10 #сотни
        if c>0 and c!=0:
            for i in range(2,int(c**0.5)+1):
                if c%i==0:
                     k+=1
            if k==0:
                maxx=max(maxx, c)
            else:
                k=0
        n=n//10 #тысячи
        if n>0 and n!=0:
            for i in range(2,int(n**0.5)+1):
                if n%i==0:
                     k+=1
            if k==0:
                maxx=max(maxx, n)
            else:
                k=0
        kom1=n*10+c
        if kom1>0 and kom1!=0:
            for i in range(2,int(kom1**0.5)+1):
                if kom1%i==0:
                     k+=1
            if k==0:
                maxx=max(maxx, kom1)
            else:
                k=0
        kom2=c*10+b
        if kom2>0 and kom2!=0:
            for i in range(2,int(kom2**0.5)+1):
                if kom2%i==0:
                     k+=1
            if k==0:
                maxx=max(maxx, kom2)
            else:
                k=0
        kom3=b*10+a
        if kom3>0 and kom3!=0:
            for i in range(2,int(kom3**0.5)+1):
                if kom3%i==0:
                     k+=1
            if k==0:
                maxx=max(maxx, kom3)
            else:
                k=0
        kom4=n*100+c*10+b
        if kom4>0 and kom4!=0:
            for i in range(2,int(kom4**0.5)+1):
                if kom4%i==0:
                     k+=1
            if k==0:
                maxx=max(maxx, kom4)
            else:
                k=0
        kom5=c*100+b*10+a
        if kom5>0 and kom5!=0:
            for i in range(2,int(kom5**0.5)+1):
                if kom5%i==0:
                     k+=1
            if k==0:
                maxx=max(maxx, kom5)
            else:
                k=0
        print(maxx)
else:
    print('0')
